﻿@{
    ViewData["Title"] = "Home Page";
}


<div>
    msg:<input type="text" style="width:200px;height:30px;margin-left:5px;margin-right:5px;" id="txt_msg" />
    <input type="button" value="send" id="btn_send" />
</div>

<div class="text-center">
    <h1 class="display-4">Welcome</h1>
    <p>Learn about <a href="https://docs.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>
</div>


@section Scripts{
    <script>
        $(function () {

            $("#btn_send").on("click", function () {
                var msg = $("#txt_msg").val();
                var msgView = {
                    content: msg
                }

                $.ajax({
                    url: "/Home/SendMsg",
                    type: "post",
                    dataType: "json",
                    data: JSON.stringify(msgView),
                    contentType: "application/json; charset=utf-8",
                    success: function (data) {
                        if (data.flag == 0) {
                            alert("ok")
                        }
                        else {
                            alert(data.msg);
                        }
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        alert(errorThrown);
                    }
                });
            })

        });
    </script>
}
